<?php

namespace app\models;

use app\admin\service\CommonService;
use think\Model;

/**
 * 跟进沟通记录表
 * Class FollowUpLogModel
 * @package app\models
 */
class FollowUpLogModel extends Model
{
    protected $table = 'edu_follow_up_log';

    /**
     * 跟进沟通记录.
     *
     * @param $param
     *
     * @throws \think\Exception
     * @throws \think\exception\DbException
     *
     * @return array
     */
    public function getCustomerFollowUpLists($param)
    {
        $page = isset($param['page']) ? (int) $param['page'] : 1;
        $listRows = isset($param['limit']) ? (int) $param['limit'] : 10;
        $where = [];

//        if(get_current_type() == 5){  //员工级别
//            $where['user_id'] = get_current_id();
//        }

        if (isset($param['day']) && '' !== $param['day']) {
            $date = explode(' - ', $param['day']);
            $start = $date[0];
            $end = $date[1];
            $where['date'] = [['egt', $start], ['elt', $end]];
        }
//		if(get_current_type() == 4 || get_current_type() == 5){
//			$where['campus_id'] = get_current_campus_id();
//		}elseif (get_current_type() == 2 || get_current_type() == 3){
//			$where['campus_id'] = ['in',get_current_campus_id()];
//		}
        $listData = self::where($where)->order('date desc')
            ->paginate($listRows, false, ['page' => $page])
            ->toArray();

        if (!empty($listData)) {
            foreach ($listData['data'] as &$item) {
                $item['name'] = StudentModel::get($item['student_id'])['student_name'];
                $item['phone'] = StudentModel::get($item['student_id'])['phone'];
                $item['register_date'] = StudentModel::get($item['student_id'])['register_date'];
                $item['campus'] = CampusModel::get($item['campus_id'])['campus_name'];
                $item['user_name'] = UserModel::get($item['user_id'])['name'];
            }
        }

        return $listData;
    }
}
